﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
using System.Data.SqlClient;
using System.Data;
using MySql.Data.MySqlClient;

namespace DAL
{
  public   class OperatorDAL
    {
      public Operator GetBuUsername(string username){
          DataTable dt = SqlHelper.ExecuteDataTable("select * from user where username=@username and isdel=0", 
              new MySqlParameter("@username", username));
          if (dt.Rows.Count <= 0) {
              return null;
          }
          else if (dt.Rows.Count > 1)
          {
              throw new Exception("存在重复用户名");
          }
          else {
              return ToOperator(dt.Rows[0]);
          }
      }
      private Operator ToOperator(DataRow dr) {
          Operator op = new Operator();
          op.Uid = (int)dr["uid"];
          op.Username = dr["username"].ToString();
          op.Password = dr["password"].ToString();
          op.IsAdmin = dr["isadmin"].ToString();
          op.isdel = dr["isdel"].ToString();
          return op;

      }
    }
}
